<template>
  <el-select v-model="svalue" :disabled="disabled" filterable clearable :placeholder="$t('请选择')" @change="changeHandle">
    <el-option
      v-for="item in investOptions"
      :key="item.fundId"
      :label="item.fundName"
      :value="item.fundId"
    />
  </el-select>
</template>

<script>
import { findInvestFundInfo } from '@/api/fund/lpBase/lpBase'

export default {
  props: {
    value: {
      type: String,
      default: ''
    },
    // 基金ID
    lpId: {
      type: String,
      default: () => ''
    },
    // 是否禁用
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      svalue: this.value,
      investOptions: []
    }
  },
  watch: {
    value(newVal) {
      this.svalue = newVal
    },
    svalue(newVal, oldVal) {
      if (newVal !== oldVal) {
        this.$emit('input', this.svalue)
        // this.$emit('change', this.svalue)
      }
    },
    lpId: {
      handler() {
        this.fundFund()
      }
    }
  },
  mounted() {
    this.fundFund()
  },
  methods: {
    fundFund() {
      const obj = {
        id: this.lpId
      }
      findInvestFundInfo(obj).then(response => {
        this.investOptions = response.rows
        console.log(this.investOptions)
      })
    },
    changeHandle() {
      this.$emit('change', this.svalue)
    }
  }
}
</script>
